<?php
//    1. 数组函数count
$arr = ["orange", "watermelon", "cherry"];
$count = count($arr);
echo $count;

//    2. array_map
$arr1 = [1, 2, 3, 4, 5];
function myfunction($num)
{
    return $num * $num;
}

$data1 = array_map("myfunction", $arr1);
echo "<pre>";
print_r($data1);
echo "</pre>";

//    3. in_array
if (in_array("apple", $arr)) {

}
$trueorfalse = in_array("orange", $arr);
echo $trueorfalse;
echo "<br/>";

//    4. 数组转字符串 implode
$arrayToString = implode(",", $arr);
echo $arrayToString;

//    5. 字符串转数组 explode
$stringToArray = explode(",", $arrayToString);
echo "<pre>";
print_r($stringToArray);
echo "</pre>";

//    6. array_keys
$keys = array_keys($arr);
echo "<pre>";
print_r($keys);
echo "</pre>";

//     7. array_values
$values = array_values($arr);
echo "<pre>";
print_r($values);
echo "</pre>";

//    8. array_diff
$diff1 = ["apple","banana","peach","pear"];
$diff2 = ["apple","melon","peach","mango"];
$result = array_diff($diff1,$diff2);
echo "<pre>";
print_r($result);
echo "</pre>";

//    9. array_combine diff1作为key, diff2作为values
$combine = array_combine($diff1,$diff2);
echo "<pre>";
print_r($combine);
echo "</pre>";

//    10. array_merge数组合并
$merge = array_merge($diff1,$diff2);
echo "<pre>";
print_r($merge);
echo "</pre>";


